package uk.ac.bath.machine.neural;



import java.util.Enumeration;
import java.util.Vector;
import uk.ac.bath.base.MachineIF;
import uk.ac.bath.util.Tweakable;

import uk.ac.bath.base.RecursiveMachine;
import uk.ac.bath.base.MappedOperator;
import uk.ac.bath.base.PalleteIF;
import uk.ac.bath.util.MyRandom;
import uk.ac.bath.util.TweakableDouble;

public class NeuralMachine extends RecursiveMachine {

  //  final static public Value protoValue = new Value(0.0);
  
    public static Vector<Tweakable> tweaks = new Vector<Tweakable>();
    public static TweakableDouble maxValue = new TweakableDouble(tweaks, 0.0, 100.0, 2.0, 1.0, "MaxValue");
 
    
    public NeuralMachine(Vector<MappedOperator> unitList,PalleteIF pallete) {
        super(unitList,pallete);
    }

    public NeuralMachine(int nOps,PalleteIF pallete) {
        super(nOps,pallete);

    }

    @Override
    public Object clone() throws CloneNotSupportedException {
        Vector<MappedOperator> newList = new Vector<MappedOperator>(size);
        for (Enumeration e = unitList.elements(); e.hasMoreElements();) {
            MappedOperator o = (MappedOperator) (((MappedOperator) (e.nextElement())).clone());
            newList.add(o);
        }
        return new NeuralMachine(newList,pallete);
    }


    public int sizeIn() {
        return size;
    }

    public int sizeOut() {
        return size;
    }

   
    public NeuralMachine splice(MachineIF bx) throws CloneNotSupportedException {

        NeuralMachine a=this;
        NeuralMachine b=(NeuralMachine)bx;

        NeuralMachine head;
        NeuralMachine tail;

        if (a.size() > b.size()) {
            head = b;
            tail = a;
        } else {
            head = a;
            tail = b;
        }

        int crossPoint = MyRandom.nextInt(head.size());
        int sizeX = tail.size();

        Vector<MappedOperator> opList = new Vector<MappedOperator>(sizeX);
        for (int i = 0; i < sizeX; i++) {
            if (i < crossPoint) {
                opList.add(head.cloneOpAt(i));
            } else {
                opList.add(tail.cloneOpAt(i));
            }
        }


        NeuralMachine machine = new NeuralMachine(opList,pallete);

        return machine;

    }

  
  
   
}
